package com.ruoyi.back.controller

import com.ruoyi.app.common.Data
import com.ruoyi.app.common.PageData
import com.ruoyi.app.common.pageInfo
import com.ruoyi.back.domain.Member
import com.ruoyi.back.domain.dto.ExperienceMemberDto
import com.ruoyi.back.domain.dto.UpdateVideoSingleMemberDto
import com.ruoyi.back.domain.vo.UpdateVideoSingleMemberVo
import com.ruoyi.back.service.MemberService
import io.swagger.annotations.Api
import io.swagger.annotations.ApiImplicitParam
import io.swagger.annotations.ApiImplicitParams
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("system/member")
@Api(tags = ["会员管理"])
class MemberController {

    @Autowired
    private lateinit var memberService: MemberService


    @ApiOperation("保存会员")
    @PostMapping("save")
    fun saveMember(@RequestBody member: Member): Data<Boolean> = memberService.saveMember(member)

    /**
     * 设置选中
     */
    @ApiOperation("设为选中")
    @GetMapping("setDefault/{memberId}")
    fun setDefault(@PathVariable memberId: Long): Data<Boolean> = memberService.setDefault(memberId)

    @ApiOperation("会员分页")
    @GetMapping("list")
    fun memberPage(): PageData<Member> = memberService.memberPage().pageInfo()

    @ApiOperation("批量移除会员")
    @ApiImplicitParams(
        ApiImplicitParam(name = "memberIds", value = "会员id 多个使用逗号", type = "path", required = true)
    )
    @GetMapping("remove/{memberIds}")
    fun removeMember(@PathVariable memberIds: String): Data<Boolean> = memberService.removeMember(memberIds)

    @ApiOperation("编辑体验会员")
    @PostMapping("updateExperienceMember")
    fun updateExperienceMember(@RequestBody experienceMemberDto: ExperienceMemberDto): Data<Boolean> =
        memberService.updateExperienceMember(experienceMemberDto)

    @ApiOperation("编辑视频单次收费")
    @PostMapping("updateVideoSingleMember")
    fun updateVideoSingleMember(@RequestBody updateVideoSingleMemberDto: UpdateVideoSingleMemberDto): Data<Boolean> =
        memberService.updateVideoSingleMember(updateVideoSingleMemberDto)

    @ApiOperation("获取视频单条收费详情")
    @GetMapping("getUpdateVideoSingleMemberDetail")
    fun getUpdateVideoSingleMemberDetail(memberId: Long): Data<UpdateVideoSingleMemberVo> =
        memberService.getUpdateVideoSingleMemberDetail(memberId)
}